<?php
/**
 * 生成全局唯一ID
 *
 * Author: JennyWang
 * Date: 2018/4/11
 * Time: 21:27
 * Created by PhpStorm.
 */

namespace App\Services\Utils;

use App\Models\Currency;

class FormatPrice
{
    public static function format($price, Currency $currency)
    {
        $format_price = self::formatPrice($price, $currency);

        $symbol_left = $currency->symbol_left;
        $symbol_right = $currency->symbol_right;

        // 后台是可以同时设置左右符号的，默认取左边的符号
        if ($symbol_left) {
            return $symbol_left . $format_price;
        } else {
            return $format_price . $symbol_right;
        }
    }

    /**
     * @deprecated - 请直接使用 $currency->exchangePrice($price)
     *
     * @param $price
     * @param Currency $currency
     *
     * @return string
     */
    public static function formatPrice($price, Currency $currency)
    {
        return $currency->exchangeOptionValuePrice($price);
    }

    /**
     * @param $currency
     * @param $price
     * @param int $decimal_place
     * @return string
     */
    public static function formatPriceToCny($currency, $price, $decimal_place = 4)
    {
        return bcdiv($price, $currency->value, $decimal_place);
    }
}